Imports MIMS.WRS.Business
Imports MIMS.WRS.Entities


Public Class StartPage
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents ltrOffice As System.Web.UI.WebControls.Literal
    Protected WithEvents ddlOffices As System.Web.UI.WebControls.DropDownList
    Protected WithEvents lnkSwitchOffice As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents Dropdownlist1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlConPoint As System.Web.UI.WebControls.DropDownList
    Protected WithEvents divViewSaleOrders As System.Web.UI.HtmlControls.HtmlGenericControl

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

   

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' get current user office
        Security.DenyIDSUser()

        Me.ltrOffice.Text = OfficeService.GetOffice(RequestContext.CurrentUser.ActiveOfficeID).OfficeName

        AjaxPro.Utility.RegisterTypeForAjax(GetType(MIMS_WRS.Web.AjaxUtilMethod))
       
        If Not IsPostBack Then
            Try
                divViewSaleOrders.Visible = RequestContext.CurrentUser.ViewSalesOrders()
                If (MIMS_WRS.Web.RequestContext.CurrentUser.IS_ADMIN) Then
                    divViewSaleOrders.Visible = True
                End If
            Catch ex As Exception
            End Try

            ' get list of available office for this user
            Me.ddlOffices.DataSource = OfficeService.GetOffices(RequestContext.CurrentUser.US_ID_PK)
            Me.ddlOffices.DataTextField = OfficeColumns.OfficeName.ToString()
            Me.ddlOffices.DataValueField = OfficeColumns.OfficeID.ToString()
            Me.ddlOffices.DataBind()

            Me.ddlOffices.SelectedIndex = Me.ddlOffices.Items.IndexOf(Me.ddlOffices.Items.FindByValue(RequestContext.CurrentUser.ActiveOfficeID.ToString()))

            Me.ddlConPoint.DataSource = ConPointService.GetConPoints(ConPointColumns.Description, MyFramework.OrderDirection.ASC)
            Me.ddlConPoint.DataTextField = ConPointColumns.Description.ToString()
            Me.ddlConPoint.DataValueField = ConPointColumns.ConPointID.ToString()
            Me.ddlConPoint.DataBind()
            Me.ddlConPoint.Items.Insert(0, New ListItem("[--select con point--]", "-1"))

            If (RequestContext.SelectedSupplier <> "") Then
                Dim conPointID As Integer = ConPointService.GetConPointBySupplier(RequestContext.SelectedSupplier)
                Try
                    ddlConPoint.SelectedIndex = ddlConPoint.Items.IndexOf(ddlConPoint.Items.FindByValue(conPointID.ToString()))
                Catch ex As Exception

                End Try
            End If
        End If
    End Sub

    Private Sub lnkSwitchOffice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkSwitchOffice.Click
        Dim userObj As MIMS.WRS.Entities.USER = USERService.GetUSER(RequestContext.CurrentUser.US_ID_PK)
        userObj.ActiveOfficeID = Integer.Parse(Me.ddlOffices.SelectedItem.Value)
        USERService.UpdateUSER(userObj)
        RequestContext.CurrentUser = userObj
        RequestContext.CurrentOffice = OfficeService.GetOffice(RequestContext.CurrentUser.ActiveOfficeID)
        Response.Redirect(Request.RawUrl)
    End Sub



End Class

